﻿namespace com.stifel.BranchMgmt
{
    using System.Collections.Generic;
    using System.Reflection;
    using System.Web.UI.WebControls;

    using com.stifel.BranchMgmtDao;
    using com.stifel.Extensions.AssemblyExtensions;

    using Microsoft.SharePoint;

    public partial class BranchMgmtViewUserControl
    {
        #region Methods

        void loadUpdates( int branchId )
        {
            const string TITLE = "%title";
            const string NOTES = "%notes";
            const string CREATED = "%created";
            const string AUTHOR = "%author";

            const string DATESTRING = "M/d/yyyy h:mm tt";

            const string TEMPLATE = "BranchMgmtViewUserControl_Updates.htm";

            StifelBranchUpdateDao dao = new StifelBranchUpdateDao( SPContext.Current.Web.Url );
            List<StifelBranchUpdate> value = dao.GetByBranchLocation( branchId );

            string templatefqn = Assembly.GetExecutingAssembly( ).GetFullyQualifiedManifestResourceName( TEMPLATE );
            string template = Assembly.GetExecutingAssembly( ).GetManifestResourceAsString( templatefqn );

            foreach ( StifelBranchUpdate o in value )
            {
                string s = template
                    .Replace( TITLE, o.Title )
                    .Replace( CREATED, o.Created.ToString( DATESTRING ) )
                    .Replace( AUTHOR, o.Author.LoginName )
                    .Replace( NOTES, o.UpdateNotes );

                uiUpdate.Controls.Add( new Literal
                {
                    Text = s
                } );
            }
        }

        #endregion Methods
    }
}